﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace _06_Events
{
    class Program
    {
        ManualResetEvent manual = new ManualResetEvent(false); //unsignalled
        //AutoResetEvent auto = new AutoResetEvent(false);

        void Thread1()
        {
            Console.WriteLine("id: {0}; wait for event", Thread.CurrentThread.ManagedThreadId);
            manual.WaitOne();
            //auto.WaitOne();
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("id: {0}; i = {1}", Thread.CurrentThread.ManagedThreadId, i);
                Thread.Sleep(100);
            }
            //auto.Set();
        }

        static void Main(string[] args)
        {
            Program pr = new Program();
            new Thread(pr.Thread1).Start();
            new Thread(pr.Thread1).Start();
            new Thread(pr.Thread1).Start();

            Console.ReadKey();
            pr.manual.Set();    //signalled
            //pr.auto.Set();
        }
    }
}
